//
//  MainCell5.m
//  ShopXinyi
//
//  Created by qianfeng on 15/9/16.
//  Copyright (c) 2015年 qianfeng. All rights reserved.
//

#import "MainCell5.h"
#import "MainGoodsModel.h"
#import "UIImageView+AFNetworking.h"
#import "MainDiscountCell.h"


@implementation MainCell5

- (void)awakeFromNib {
    // Initialization code
    [_myCollectionView registerNib:[UINib nibWithNibName:@"MainDiscountCell" bundle:nil ] forCellWithReuseIdentifier:@"MainDiscountCell"];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


#pragma mark -UICollectionViewDataSource

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}
//cell 复用
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MainDiscountCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MainDiscountCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"MainDiscountCell" owner:self options:0][0];
    }
    if (self.dataArray.count > 0) {
        MainGoodsModel *model = self.dataArray[indexPath.row];
        [cell.imageView setImageWithURL:[NSURL URLWithString:model.goodsImg]];
        cell.nameLabel.text = model.goodsName;
        cell.nowPrice.text = model.goodsPrice;
        cell.beforePrice.text = [NSString stringWithFormat:@"￥ %@",model.goodsMKPrice];
        
    }
    
    return cell;
}

//cell的尺寸
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGSize size = CGSizeMake(self.frame.size.width/3.0 - 10, self.frame.size.width/3.0*1.4);
    return size;
}

@end
